package club.ljwang.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;

import java.util.ArrayList;
import java.util.Date;

/**
 * @Auther: wangl
 * @Date: 2020/3/10 00:37
 * @Description:
 */
public class Test {
    public static void main(String[] args) {
        String dateStr1 = "2017-03-01";
        Date date1 = DateUtil.parse(dateStr1);
        String dateStr2 = "2017-04-01";
        Date date2 = DateUtil.parse(dateStr2);

        long betweenDay = DateUtil.between(date1, date2, DateUnit.DAY);
        System.out.println("betweenDay = " + betweenDay);
        ArrayList<String> days = new ArrayList<>();
        for (int i = 0; i <= betweenDay; i++) {
            DateTime day = DateUtil.offsetDay(date1,i);
            days.add(day.toString("yyyyMMdd"));
        }

        System.out.println("months = " + days);
    }
}
